
#!/bin/sh
src="$1"
dst="$2"
shift 2

if [ ! -f "$src" ]; then
	echo "usage: app2dylib.sh <src> <dst> [armv7 armv7s arm64 i386 x86_64]"
	exit
fi

if [ '' = "$1" ]; then
	"$0" "$src" "$dst" armv7 armv7s arm64 i386 x86_64
	exit
fi

param="lipo -create -o '$dst'"
for a in "$@"; do
	lipo -thin "$a" "$src" -o "$src.$a" 2>/dev/null
	[ -f "$src.$a" ] && app2dylib "$src.$a" -o "$src.$a.dylib"
	[ -f "$src.$a.dylib" ] && param="${param} '$src.$a.dylib'"
done

eval "$param"

for a in "$@"; do
	rm -f "$src.$a"
	rm -f "$src.$a.dylib"
done

lipo -info "$dst"

exit

